package svc

import (
	"center-data-platform/app/user/api/model"
	"center-data-platform/app/user/rpc/internal/config"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

type ServiceContext struct {
	Config config.Config
	User   model.User
	DB     *gorm.DB
}

func NewServiceContext(c config.Config) *ServiceContext {
	gormDB, err := gorm.Open(mysql.Open(c.Mysql.Datasource), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	if err != nil {
		panic(err)
	}
	return &ServiceContext{
		Config: c,
		DB:     gormDB,
	}
}
